﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            ServiceCollection service = new ServiceCollection();

            service.AddScoped<Test1>();

            //添加日志文件
            ConfigurationBuilder configBuilder = new ConfigurationBuilder();
            configBuilder.AddJsonFile("config.json", false, true);
            var configRoot = configBuilder.Build();

            service.AddOptions().Configure<Employee>(e => configRoot.GetSection("Employee").Bind(e));

            using (var sp = service.BuildServiceProvider())
            {
                var t1 = sp.GetRequiredService<Test1>();
                t1.Test();
            }


            

            //Console.WriteLine(configRoot["Name"]);
            //MyConfig config = configRoot.Get<MyConfig>();

            //Console.WriteLine($"{config.Name}, {config.IP}");
        }

        static async Task DownloadAsync(string url, string filePath)
        {
            using (HttpClient httpClient = new HttpClient())
            {
                string body = await httpClient.GetStringAsync(url);
                await File.WriteAllTextAsync(filePath, body);
            }
        }
    }

    public class MyConfig
    {
        public string? Name { get; set; }

        public string? IP { get; set; }
    }
}
